home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************/
- /* Universal Vertical Menu 11:03:45 5/3/1986 */
- /* */
- /* courtesy of Dr. Bob's Utilities */
- /* */
- /* This function prints a standard vertical menu on the screen */
- /* hilighting the current option in various ways. It lets you */
- /* select the menu choice by number or by using the arrow or */
- /* home and end keys. */
- /* It beeps at unacceptable key choices and returns the */
- /* integer value of the final selection. */
- /* */
- /* INPUT - the function is sent four arguments: */
- /* */
- /* 1. The title of the menu - char *title */
- /* 2. A pointer to the array of choices - char *options[] */
- /* note that all choices have at least to leading and */
- /* trailing blanks and that all are the same length. */
- /* If this seems too wasteful to you, you can modify the code. */
- /* Also note that the array must end with a null string. */
- /* */
- /* 3. Row of the upper left corner of the menu - int row, col */
- /* 4. Column of the upper left corner of menu. */
- /* If row and col are both 0, the function automatically */
- /* centers the menu on the screen. */
- /* */
- /* FUNCTIONS YOU MAY NOT HAVE: */
- /* */
- /* 1. cursoff() - turns cursor off. Not necessary but improves look. */
- /* 2. smallcurs() - turns cursor back on. Both included. */
- /* 3. cls() - clears screen, homes cursor. */
- /* 4. locate() - places cursor. (N.B. 1,1 is upper left corner) */
- /* 5. inch() - waits for and returns key from keyboard. */
- /* included - calls kb() also included. */
- /* 6. boop() - inoffensive beep, included. */
- /* 7. box()- draws a box, I'd give it to you but I don't own it. */
- /* box(ul_row,ul_col,lr_row,lr_col) */
- /* hint: If you write one, draw the box clockwise from the upper */
- /* left corner. Do the corners as you come to them, */
- /* if you wait and do them at the end it will look */
- /* dopey. */
- /* */
- /* FUNCTIONS YOU MAY WANT TO MODIFY: */
- /* */
- /* 1. printf() - My printf function uses the int attr to determine */
- /* color and characteristics. I don't own it so I can't give it */
- /* to you. If yours doesn't do this you can modify it (or write */
- /* a substitute function). You can also just use the code as */
- /* is since the asterisks will still hilight the current choice. */
- /* The menu function redraws the whole menu each time a key is */
- /* pressed. My printf() is in assembly language so this is not */
- /* noticable. If yours is slow, you may want to rewrite the */
- /* function to minimize redraws. */
- /* */
- /* Courtesy of: Dr. Bob's Utilities */
- /* 444 Maple Lane */
- /* St. Paul MN 55126 */
- /* */
- /* You can find Bob Ray on Terrapin Station BBS! */
- /* A Programmer's BBS - 612/623-0152 */
- /* 1200/2400 24 hours a day! */
- /* */
- /* */
- /**************************************************************************/
-
-
- #include keys.h
-
- #define test 1
-
-
- #define ON 1 /* use 1 for underline, 112 for inverse, */
- /* 15 for hilight, 135 for blink */
-
- #define OFF 7 /* normal */
-
- #ifdef test
- int attr = 7;
-
- main()
- {
- int choice;
- char temp[20];
- static char *options[] = {
- " 1. Menu choice number one ",
- " 2. Menu choice number two ",
- " 3. Menu choice number three ",
- " 4. Exit the program ",
- ""
- };
-
-
- choice = umenu("MAIN MENU",options,0,0);
-
- locate(20,5);
- printf("You picked %d\n",choice);
-
- }
- #endif;
-
- umenu(title,options,row,col)
- char *title;
- char *options[];
- int row, col;
-
- {
- extern int attr;
- int count;
- int maxlen;
- int i;
- int active;
- int done;
- int ch;
-
-
- count = 0;
- active = 0;
-
- cursoff();
-
- while(*options[++count]) /* count number of menu choices */
- ;
-
- maxlen = strlen(options[1]);
-
- printf("\nMaxlen = %d\n",maxlen);
- cls();
-
- if ( (row + col) == 0) { /* center the menu automatically */
- row = 13 - (count/2);
- col = 41 - (maxlen/2);
- }
-
- locate(row-2,col - 4 + (maxlen/2) );
- printf("%s",title);
-
- box(row-4,col-2,row+count+1,col + maxlen + 2);
- done = 0;
-
- do {
- for (i = 0; i < count; i++) {
- locate(row + i,col);
- if (i == active)
- attr = ON;
- else attr = OFF;
-
- printf("%s",options[i]);
- if(i == active) {
- printf("\b*");
- locate(row+i,col);
- printf("*");
- }
-
- }
- ch = inch();
- if ( (ch >= '1') && (ch <= ('0' + count) ) ) {
- active = ch - '1';
- continue;
- }
- switch(ch) {
- case('\r'):
- case ('q'): /* SAFETY FIRST - REMOVE THIS IF CR works */
- done = 1;
- break;
- case HM:
- active = 0;
- break;
- case END:
- active = count -1;
- break;
- case DN:
- case RIGHT:
- if(active == count-1)
- active = 0;
- else
- active++;
- break;
-
- case UP:
- case LEFT:
- if(active == 0)
- active = count - 1;
- else
- active--;
- break;
-
-
-
- default:
- boop();
- break;
-
- }
-
- } while ( !done);
-
- smallcurs();
- attr = OFF;
- return(active +1);
-
- }
-